package com.itqf.Service.User.Impl;

import com.itqf.Dao.UserCenterMapper;
import com.itqf.Service.User.UserCenter;
import com.itqf.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 李鹏鹏
 * @version 1.0
 * @ClassName: UserCenterService
 * @Description: TODO
 * @Date 2019/10/18 0018 下午 8:20
 * @since JDK 1.8
 */
@Service
@Transactional
public class UserCenterServiceImpl implements UserCenter {

    @Resource
    private UserCenterMapper userCenterMapper;

    /** @Description: 根据token修改用户昵称
     * @Param:
     * @return:
     * @Author: 李鹏鹏
     * @Date: 下午 8:18
     */

    @Override
    @Transactional
    public int updateName(String userNickName, String userid) {
        Map map=new HashMap();
        map.put("name", userNickName);
        map.put("userid", userid);
        return userCenterMapper.updateNameByToken(map);
    }

    /** @Description: 根据Token更换头像
     * @Param:
     * @return:
     * @Author: 李鹏鹏
     * @Date: 下午 8:18
     */
    @Override
    @Transactional
    public int updateIconByToken(String originalFilename, String userid) {
        Map map=new HashMap();
        map.put("icon", originalFilename);
        map.put("userid", userid);
        return userCenterMapper.upadteIconByToken(map);
    }

    /** @Description: 根据Token更换手机号
     * @Param:
     * @return:
     * @Author: 李鹏鹏
     * @Date: 下午 8:18
     */
    @Override
    @Transactional
    public int updatePhoneByToken(String userPhone, String userid) {
        Map map=new HashMap();
        map.put("userPhone", userPhone);
        map.put("userid", userid);
        return userCenterMapper.updatePhoneByToken(map);
    }


    /** @Description: 根据Token返回user对象
     * @Param:
     * @return:
     * @Author: 李鹏鹏
     * @Date: 下午 8:17
     */
    @Override
    public User findbytoken(String userid) {
        return userCenterMapper.findbytoken(userid);
    }
}
